package cn.pugle.base.annotation;

import java.lang.reflect.Field;

/**
 * Created by tzp on 15-10-21.<br>
 */
@HaveColor()
public class Apple implements Eatable {

    @HaveName(name = "xiao 苹果")
    public String myName;
    private String mySize = "80 66";

    @Override
    public String toString() {
        return this.getClass().getName() + " : " + myName;
    }

    public static void main(String[] args) throws Exception {
        Apple apple = new Apple();
        HaveColor annotation = apple.getClass().getAnnotation(HaveColor.class);
        System.out.println(annotation.colorName());

        Field myNameField = apple.getClass().getField("myName");
        myNameField.set(apple, myNameField.getAnnotation(HaveName.class).name());
        System.out.println(apple.toString());

        Field privateField = apple.getClass().getDeclaredField("mySize");
        privateField.setAccessible(true);
        System.out.println(privateField.get(apple));
    }

    @Override
    public String taste() {
        return Eatable.TASTE_TIAN;
    }
}
